|
RPi Hardware Interface
|
#include <stdint.h>#include <stdbool.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <getopt.h>#include <fcntl.h>#include <time.h>#include <sys/ioctl.h>#include <string.h>#include <errno.h>#include <linux/types.h>#include <linux/spi/spidev.h>#include <linux/i2c.h>#include <linux/i2c-dev.h>#include <jni.h>#include <jni_md.h>#include "CommandDefinitions.h"#include "etada_netio_jni_HardwareIO.h"Typedefs | |
| typedef uint64_t | spi_ptr_container_t |
Functions | |
| void | throwIOException (JNIEnv *env, const char *message) |
| int | openI2CDevice (JNIEnv *env, jobject deviceHandleInst) |
| void | closeI2CDevice (int fileHandle) |
| int | i2c_transmission (int fileHandle, uint8_t address7bit, bool write_mode, uint8_t *data_buffer, size_t buffer_size) |
| void | showByteArray (char *cStr, uint8_t *byteArray, int32_t maxTextSize, int32_t arraySize) |
| char * | getDevicePath (JNIEnv *env, jobject deviceHandleInst) |
| uint32_t | readIntFromByteArray (uint8_t *byteArray, size_t intIndex) |
| void | writeIntToByteArray (uint8_t *byteArray, size_t intIndex, uint32_t i) |
| struct spi_ioc_transfer * | allocSPITransferStruct (uint16_t delay, uint32_t speed_Hz, uint8_t bits_per_word, uint8_t *sendBuffer, uint8_t *receiveBuffer, uint32_t length) |
| int | spiPacket (JNIEnv *env, int fileHandle, struct spi_ioc_transfer *packetInfo) |
| int | openSPIDevice (JNIEnv *env, jint speed_Hz, jbyte spiMode, jbyte bits_per_word, jobject deviceHandleInst) |
| void | closeSPIDevice (int fileHandle) |
| JNIEXPORT void JNICALL | Java_etada_netio_jni_HardwareIO_bitmaskSequence (JNIEnv *env, jobject inst, jintArray bitmasks, jintArray durations, jint speed_Hz, jbyte mode, jbyte bits_per_word, jshort delay, jlong timeout_ms, jobject deviceHandleInst) |
| JNIEXPORT void JNICALL | Java_etada_netio_jni_HardwareIO_bitmaskLargeDataSequence (JNIEnv *env, jobject inst, jintArray bitmasks, jintArray durations, jshortArray adcBuffer0, jshortArray adcBuffer1, jshortArray adcBuffer2, jshortArray adcBuffer3, jint speed_Hz, jbyte mode, jbyte bits_per_word, jshort delay, jlong timeout_ms, jobject deviceHandleInst) |
| JNIEXPORT jintArray JNICALL | Java_etada_netio_jni_HardwareIO_dataRecordStream (JNIEnv *env, jobject inst, jintArray addresses_24bit, jint speed_Hz, jbyte mode, jbyte bits_per_word, jshort delay, jobject deviceHandleInst) |
| JNIEXPORT jbyteArray JNICALL | Java_etada_netio_jni_HardwareIO_spi (JNIEnv *env, jobject inst, jint speed_Hz, jbyte mode, jbyte bits_per_word, jshort delay, jbyteArray master_out, jobject deviceHandleInst) |
| JNIEXPORT void JNICALL | Java_etada_netio_jni_HardwareIO_writeI2CData (JNIEnv *env, jobject classInst, jbyte address, jbyteArray data, jobject deviceHandle) |
| JNIEXPORT jbyteArray JNICALL | Java_etada_netio_jni_HardwareIO_readI2CData (JNIEnv *env, jobject classInst, jbyte address, jint dataSize, jobject deviceHandle) |
| char | toHex (uint8_t digit) |
Variables | |
| jclass | DeviceHandle_class = NULL |
| jmethodID | DeviceHandle_method = NULL |
| char | hexDigits [16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'} |
| typedef uint64_t spi_ptr_container_t |
| struct spi_ioc_transfer * allocSPITransferStruct | ( | uint16_t | delay, |
| uint32_t | speed_Hz, | ||
| uint8_t | bits_per_word, | ||
| uint8_t * | sendBuffer, | ||
| uint8_t * | receiveBuffer, | ||
| uint32_t | length | ||
| ) |
| void closeI2CDevice | ( | int | fileHandle | ) |
| void closeSPIDevice | ( | int | fileHandle | ) |
| char * getDevicePath | ( | JNIEnv * | env, |
| jobject | deviceHandleInst | ||
| ) |
| int i2c_transmission | ( | int | fileHandle, |
| uint8_t | address7bit, | ||
| bool | write_mode, | ||
| uint8_t * | data_buffer, | ||
| size_t | buffer_size | ||
| ) |
| JNIEXPORT void JNICALL Java_etada_netio_jni_HardwareIO_bitmaskLargeDataSequence | ( | JNIEnv * | env, |
| jobject | inst, | ||
| jintArray | bitmasks, | ||
| jintArray | durations, | ||
| jshortArray | adcBuffer0, | ||
| jshortArray | adcBuffer1, | ||
| jshortArray | adcBuffer2, | ||
| jshortArray | adcBuffer3, | ||
| jint | speed_Hz, | ||
| jbyte | mode, | ||
| jbyte | bits_per_word, | ||
| jshort | delay, | ||
| jlong | timeout_ms, | ||
| jobject | deviceHandleInst | ||
| ) |
Runs a protocol consisting of a whole stack (FIFO) of timed bitmasks, using low-level data structures and driver usage to allow for very short duration timed bitmasks to prevent the SPI communication lag from violating the timing requirements. Furthermore, this function reads from the ADC data buffers during the execution of the bitmask sequence so that more data can be collected than would fit inside the on-chip FPGA memory.
Returns when the sequence is complete.
| env | The JVM environment |
| inst | Parent java object class instance |
| bitmasks | Array of 32-bit digital output masks (1 for high, 0 for low). |
| durations | The corresponding number of FPGA clock cycles to hold each bitmask |
| adcBuffer0 | data buffer to hold the expected total number of ADC records in channel 0 |
| adcBuffer1 | data buffer to hold the expected total number of ADC records in channel 1 |
| adcBuffer2 | data buffer to hold the expected total number of ADC records in channel 2 |
| adcBuffer3 | data buffer to hold the expected total number of ADC records in channel 3 |
| speed_Hz | The frequency (in bits per second) to communicate with the FPGA. See etada.netio.jni.DeviceHandle. |
| mode | The SPI communication protocol type number. See etada.netio.jni.DeviceHandle. |
| bits_per_word | The number of bits per byte. See etada.netio.jni.DeviceHandle. |
| delay | The delay between bytes in the SPI communication (none needed). See etada.netio.jni.DeviceHandle. |
| timeout_ms | Number of milliseconds to wait for the bitmask sequence to run before aborting. |
| deviceHandleInst | Instance of etada.netio.jni.DeviceHandle |
| java.io.IOException | Thrown on JVM stack if there were any detectable problems or failures while communicating with the FPGA. |
| JNIEXPORT void JNICALL Java_etada_netio_jni_HardwareIO_bitmaskSequence | ( | JNIEnv * | env, |
| jobject | inst, | ||
| jintArray | bitmasks, | ||
| jintArray | durations, | ||
| jint | speed_Hz, | ||
| jbyte | mode, | ||
| jbyte | bits_per_word, | ||
| jshort | delay, | ||
| jlong | timeout_ms, | ||
| jobject | deviceHandleInst | ||
| ) |
Runs a protocol consisting of a whole stack (FIFO) of timed bitmasks, using low-level data structures and driver usage to allow for very short duration timed bitmasks to prevent the SPI communication lag from violating the timing requirements. Returns when the sequence is complete.
| env | The JVM environment |
| inst | Parent java object class instance |
| bitmasks | Array of 32-bit digital output masks (1 for high, 0 for low). |
| durations | The corresponding number of FPGA clock cycles to hold each bitmask |
| speed_Hz | The frequency (in bits per second) to communicate with the FPGA. See etada.netio.jni.DeviceHandle. |
| mode | The SPI communication protocol type number. See etada.netio.jni.DeviceHandle. |
| bits_per_word | The number of bits per byte. See etada.netio.jni.DeviceHandle. |
| delay | The delay between bytes in the SPI communication (none needed). See etada.netio.jni.DeviceHandle. |
| timeout_ms | Number of milliseconds to wait for the bitmask sequence to run before aborting. |
| deviceHandleInst | Instance of etada.netio.jni.DeviceHandle |
| java.io.IOException | Thrown on JVM stack if there were any detectable problems or failures while communicating with the FPGA. |
| JNIEXPORT jintArray JNICALL Java_etada_netio_jni_HardwareIO_dataRecordStream | ( | JNIEnv * | env, |
| jobject | inst, | ||
| jintArray | addresses_24bit, | ||
| jint | speed_Hz, | ||
| jbyte | mode, | ||
| jbyte | bits_per_word, | ||
| jshort | delay, | ||
| jobject | deviceHandleInst | ||
| ) |
Quickly reads the ADC data recorded in the FPGA's internal data record memory, returning an array of integers where each integer is the stored value at each corresponding address in the addresses array.
| env | The JVM environment |
| inst | Parent java object class instance |
| addresses_24bit | Array of memory addresses. An address is 3 bytes stored in a 4-byte integer, where the two least significant bytes are the record number and the third least significant byte is the ADC channel (e.g. 0x00020A21 refers to record number 0x0A21 for ADC channel 2) |
| speed_Hz | The frequency (in bits per second) to communicate with the FPGA. See etada.netio.jni.DeviceHandle. |
| mode | The SPI communication protocol type number. See etada.netio.jni.DeviceHandle. |
| bits_per_word | The number of bits per byte. See etada.netio.jni.DeviceHandle. |
| delay | The delay between bytes in the SPI communication (none needed). See etada.netio.jni.DeviceHandle. |
| deviceHandleInst | Instance of etada.netio.jni.DeviceHandle |
| java.io.IOException | Thrown on JVM stack if there were any detectable problems or failures while communicating with the FPGA. |
| JNIEXPORT jbyteArray JNICALL Java_etada_netio_jni_HardwareIO_readI2CData | ( | JNIEnv * | env, |
| jobject | classInst, | ||
| jbyte | address, | ||
| jint | dataSize, | ||
| jobject | deviceHandle | ||
| ) |
Reads a series of bytes from the RPi's I2C pins.
| env | The JVM environment |
| inst | Parent java object class instance |
| address | Address to send the data to |
| dataByteCount | Number of bytes to read |
| dev | The device driver descriptor |
| java.io.IOException | Thrown if there were any detectable problems or failures while using the I2C linux driver |
| JNIEXPORT jbyteArray JNICALL Java_etada_netio_jni_HardwareIO_spi | ( | JNIEnv * | env, |
| jobject | inst, | ||
| jint | speed_Hz, | ||
| jbyte | mode, | ||
| jbyte | bits_per_word, | ||
| jshort | delay, | ||
| jbyteArray | master_out, | ||
| jobject | deviceHandleInst | ||
| ) |
Performs a single SPI communication with the FPGA and returns the bytes that were read over the course of the FPGA. The FPGA precesses the SPI data packet while it is still receiving it and thus is able to put the return data in the same SPI communication as the command. Commands are 16 bytes in length.
| env | The JVM environment |
| inst | Parent java object class instance |
| speed_Hz | The frequency (in bits per second) to communicate with the FPGA. See etada.netio.config.SPIInfo. |
| mode | The SPI communication protocol type number. See etada.netio.config.SPIInfo. |
| bits_per_word | The number of bits per byte. See etada.netio.config.SPIInfo. |
| delay | The delay between bytes in the SPI communication (none needed). See etada.netio.config.SPIInfo. |
| master_out | The SPI data packet to send. Should be 16 bytes. |
| deviceHandleInst | Instance of etada.netio.jni.DeviceHandle |
master_out containing the byte-for-byte response from the FPGA to the communication. | java.io.IOException | Thrown on JVM stack if there were any detectable problems or failures while communicating with the FPGA. |
| JNIEXPORT void JNICALL Java_etada_netio_jni_HardwareIO_writeI2CData | ( | JNIEnv * | env, |
| jobject | classInst, | ||
| jbyte | address, | ||
| jbyteArray | data, | ||
| jobject | deviceHandle | ||
| ) |
Writes a series of bytes to the RPi's I2C pins.
| env | The JVM environment |
| inst | Parent java object class instance |
| address | Address to send the data to |
| data | The bytes to send |
| dev | The device driver descriptor |
| java.io.IOException | Thrown if there were any detectable problems or failures while using the I2C linux driver |
| int openI2CDevice | ( | JNIEnv * | env, |
| jobject | deviceHandleInst | ||
| ) |
| int openSPIDevice | ( | JNIEnv * | env, |
| jint | speed_Hz, | ||
| jbyte | spiMode, | ||
| jbyte | bits_per_word, | ||
| jobject | deviceHandleInst | ||
| ) |
| uint32_t readIntFromByteArray | ( | uint8_t * | byteArray, |
| size_t | intIndex | ||
| ) |
| void showByteArray | ( | char * | cStr, |
| uint8_t * | byteArray, | ||
| int32_t | maxTextSize, | ||
| int32_t | arraySize | ||
| ) |
| int spiPacket | ( | JNIEnv * | env, |
| int | fileHandle, | ||
| struct spi_ioc_transfer * | packetInfo | ||
| ) |
| void throwIOException | ( | JNIEnv * | env, |
| const char * | message | ||
| ) |
| char toHex | ( | uint8_t | digit | ) |
| void writeIntToByteArray | ( | uint8_t * | byteArray, |
| size_t | intIndex, | ||
| uint32_t | i | ||
| ) |
| jclass DeviceHandle_class = NULL |
| jmethodID DeviceHandle_method = NULL |
| char hexDigits[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'} |